package com.example.demo.common;

import com.example.demo.model.ArticleInfo;

import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 马拉圈
 * Date: 2023-09-04
 * Time: 9:30
 */
public class ArticleUtils {

    //标题截取长度
    private static final int _TITLE_LENGTH = 40;
    //摘要截取长度
    private static final int _SUMMARY_LENGTH = 160;

    public static void substringList(List<ArticleInfo> list) {
        if(list != null && list.size() != 0) {
            // 并发处理 list 集合
            list.stream().parallel().forEach((art) -> {
                //标题截取
                if(art.getTitle().length() > _TITLE_LENGTH) {
                    art.setTitle(art.getTitle().substring(0, _TITLE_LENGTH) + "...");
                }
                //摘要截取
                if(art.getSummary().length() > _SUMMARY_LENGTH) {
                    art.setSummary(art.getSummary().substring(0, _SUMMARY_LENGTH) + "...");
                }
            });
        }
    }

}
